package leecode

import "container/list"

type Node struct {
	Val      int
	Children []*Node
}

func levelOrder429(root *Node) (result [][]int) {
	if root == nil {
		return
	}
	queue := list.New()
	queue.PushBack(root) //将根节点加入队列尾部
	//queue.Len() 获取队列长度
	for queue.Len() != 0 {
		size := queue.Len()
		temp := make([]int, 0)
		for i := 0; i < size; i++ {
			myNode := queue.Remove(queue.Front()).(*Node)
			temp = append(temp, myNode.Val)
			for j := 0; j < len(myNode.Children); j++ {
				queue.PushBack(myNode.Children[j])
			}
		}
		result = append(result, temp)
	}
	return
}
